import request from "@/utils/request";
import type { CategoryListResp, AttrInfoListResp, AttrInfo } from "./type";
enum API {
  //一级分类地址
  CATEGORY1_LIST = "/admin/product/getCategory1",
  //二级分类地址
  CATEGORY2_LIST = "/admin/product/getCategory2",
  //三级分类地址
  CATEGORY3_LIST = "/admin/product/getCategory3",
  //分类属性与属性值查询
  ATTR_LIST = "/admin/product/attrInfoList",
  //新增属性或修改属性
  SAVE_OR_UPDATE_ATTR = "/admin/product/saveAttrInfo",
  //获取属性详情
  ATTR_DETAIL = "/admin/product/getAttrValueList",
  //删除属性及属性值
  DELETE_ATTR = "/admin/product/deleteAttr",
}

export const getCategory1List = () => {
  return request.get<any, CategoryListResp>(API.CATEGORY1_LIST);
};
export const getCategory2List = (category1Id: number | undefined) => {
  return request.get<any, CategoryListResp>(
    API.CATEGORY2_LIST + `/${category1Id}`,
  );
};
export const getCategory3List = (category2Id: number | undefined) => {
  return request.get<any, CategoryListResp>(
    API.CATEGORY3_LIST + `/${category2Id}`,
  );
};
export const getAttrList = (
  category1Id: number | undefined,
  category2Id: number | undefined,
  category3Id: number | undefined,
) => {
  return request.get<any, AttrInfoListResp>(
    API.ATTR_LIST + `/${category1Id}/${category2Id}/${category3Id}`,
  );
};
export const saveOrUpdateAttr = (data: AttrInfo) => {
  return request.post<any, any>(API.SAVE_OR_UPDATE_ATTR, data);
};
export const getAttrDetail = (attrId: number | undefined) => {
  return request.get<any, AttrInfo>(API.ATTR_DETAIL + `/${attrId}`);
};
export const deleteAttr = (attrId: number | undefined) => {
  return request.delete<any, any>(API.DELETE_ATTR + `/${attrId}`);
};
